package per.ethan.javase.base;

/**
 * @author Ethan
 * @date 2020/04/26 15:23
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] numbers = {10, 5, 12, 3, 9, 125, 94, 65, 44};
        sort(numbers);
    }

    private static void sort(int[] numbers) {
        for (int i = 0; i < numbers.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < numbers.length - 1 - i; j++) {
                if (numbers[j + 1] < numbers[j]) {
                    numbers[j] = numbers[j] + numbers[j + 1];
                    numbers[j + 1] = numbers[j] - numbers[j + 1];
                    numbers[j] = numbers[j] - numbers[j + 1];
                    flag = true;
                }
            }

            if (!flag) {
                break;
            }
        }

        for (int number : numbers) {
            System.out.print(number + "\t");
        }
    }

}
